package cn.wolfcode.wolf2w.business.util;

import javax.xml.crypto.Data;
import java.util.Calendar;
import java.util.Date;

/**
 * @author 浪兎兎
 * @since 2025-06-05-8:45
 */
public class DateUtil {
    /**
     * 获取当天的最后一分一秒
     * @param date 当前时间
     * @return 最后一分一秒
     */
    public static Date getEndTime4day(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        return calendar.getTime();
    }

    /**
     * 获取当天的最后一分一秒
     * @return 最后一分一秒
     */
    public static Date getEndTime4day() {
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);
        return calendar.getTime();
    }

    /**
     * 获取两时间相差的秒数
     * @return 秒
     */
    public static long getDayBetween(Date d1, Date d2) {
        return Math.abs(d1.getTime() - d2.getTime()) / 1000;
    }
}
